home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2 (Special) / PCPro-2b.iso / Demos / Macromedia / CourseBuilder / CourseBuilderInstaller.exe / Disk1 / data1.cab / Dreamweaver-unInstalled / Configuration / Commands / Copy Support Files.js < prev    next >
Encoding:
JavaScript  |  1999-12-06  |  3.9 KB  |  146 lines

  1. // Copyright 1999 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBALS  *****************
  4.  
  5. var HELP_DOC = HELP_cmdCopySupportFiles;
  6.  
  7. var COPYALL = true;
  8. var OVERWRITE = false;
  9.  
  10. var WAS_COPIED = false;
  11.  
  12. var MAX_PATH = 50;
  13.  
  14. var VERSION_FILE = "version.txt";
  15.  
  16.  
  17. //******************* API **********************
  18.  
  19. function commandButtons(){
  20.   return new Array(BTN_OK,"cmdOK()",
  21.                    BTN_Cancel,"cmdCancel()",
  22.                    BTN_Help,"displayHelp()");
  23. }
  24.  
  25.  
  26. function cmdOK() {
  27.   copyFiles();
  28.   garbageCollect(true);
  29.   window.close();
  30. }
  31.  
  32. function cmdCancel() {
  33.   garbageCollect(true);
  34.   window.close();
  35. }
  36.  
  37.  
  38. //Checks that the image directories exist, and all the scripts.
  39. //
  40. function needToCopy() {
  41.   return (checkScripts(FILE_scriptsUrl, PREF_scriptsUrl));
  42. }
  43.  
  44.  
  45. //***************** LOCAL FUNCTIONS  ******************
  46.  
  47. function checkDirectories(theSrcDirectory, theTgtDirectory) {
  48.   var retVal = false;
  49.   var dirList, source, target, iDir;
  50.  
  51.   source = new File(theSrcDirectory);
  52.   target = new File(theTgtDirectory);
  53.   
  54.   // create the target folder
  55.   if (!target.exists()) {
  56.     retVal = true;
  57.   } else {
  58.     dirList = source.list("*.*", "dirs");
  59.     for (iDir=0; iDir < dirList.length; iDir++) {
  60.       retVal = checkDirectories(source.getAbsolutePath() + FILE_sep + dirList[iDir], 
  61.                                 target.getAbsolutePath() + FILE_sep + dirList[iDir]);
  62.       if (retVal) break;
  63.   } }
  64.   return retVal;
  65. }
  66.  
  67.  
  68. function checkScripts(theSrcDirectory, theTgtDirectory) {
  69.   var retVal = false;
  70.   var iFile, iDir, fileList, dirList;
  71.   var source, target, fromFile, toFile;
  72.  
  73.   source = new File(theSrcDirectory);
  74.   target = new File(theTgtDirectory);
  75.   
  76.   // create the target folder
  77.   if (!target.exists()) {
  78.     retVal = true;
  79.   } else {
  80.     fileList = source.list("*.*");
  81.     fromFile = new File("");
  82.     toFile = new File("");
  83.     
  84.     // check the version
  85.     toFile.setPath(target.getAbsolutePath() + FILE_sep + VERSION_FILE);
  86.     fromFile.setPath(source.getAbsolutePath() + FILE_sep + VERSION_FILE);
  87.     if (fromFile.exists()) {
  88.       if (!toFile.exists())
  89.         retVal = true;
  90.       else if (toFile.getContents() != fromFile.getContents())
  91.         retVal = true;
  92.     }
  93.     
  94.     // check the files
  95.     if (!retVal) {
  96.       for (iFile=0; iFile < fileList.length; ++iFile) {
  97.         toFile.setPath(target.getAbsolutePath() + FILE_sep + fileList[iFile]);
  98.         fromFile.setPath(source.getAbsolutePath() + FILE_sep + fileList[iFile]);
  99.         if (!toFile.exists()) {
  100.           retVal = true;
  101.           break;
  102.     } } }
  103.  
  104.     if (retVal) {
  105.       dirList = source.list("*.*", "dirs");
  106.       for (iDir=0; iDir < dirList.length; ++iDir) {
  107.         retVal = checkScripts(source.getAbsolutePath() + FILE_sep + dirList[iDir], 
  108.                               target.getAbsolutePath() + FILE_sep + dirList[iDir]);
  109.         if (retVal) break;
  110.     } }
  111.   }
  112.   return retVal;
  113. }
  114.  
  115. function copyFiles() {
  116.   window.close();
  117.   
  118.   WAS_COPIED = copySupportFiles(false, COPYALL, OVERWRITE);
  119. }
  120.  
  121. function initializeUI() {
  122.   if (!regCheck()) {
  123.     window.close();
  124.     return;
  125.   }
  126.   
  127.   var scripts = new File(PREF_scriptsUrl);
  128.   var scriptLabel = findObject("scriptsUrl");
  129.   var scriptsPath = scripts.getAbsolutePath();
  130.   if (scriptsPath.length > MAX_PATH + 3)
  131.     scriptsPath = scriptsPath.substring(0, MAX_PATH/2) + "..." + scriptsPath.substring(Math.max(0, scriptsPath.length - MAX_PATH/2));
  132.   scriptLabel.innerHTML = scriptsPath;
  133.   
  134.   var images = new File(PREF_imagesUrl);
  135.   var imageLabel = findObject("imagesUrl");
  136.   var imagesPath = images.getAbsolutePath();
  137.   if (imagesPath.length > MAX_PATH + 3)
  138.     imagesPath = imagesPath.substring(0, MAX_PATH/2) + "..." + imagesPath.substring(Math.max(0, imagesPath.length - MAX_PATH/2));
  139.   imageLabel.innerHTML = imagesPath;
  140.   
  141.   document.theForm.copyAll.checked = COPYALL;
  142.   document.theForm.overwrite.checked = OVERWRITE;
  143.   
  144. }
  145.  
  146.